public class BuildCodex {
    
    struct Request {
        
        private string Sender;
        
        private string GUID;
        
        private string Product;
        
        private string Release;
        
        private string Reference;
        
        private string Description;
        
        private string[] Sourcefiles;
        
        private string[] Components;
        
        private string[] SQL;
        
        private string Impact;
        
        private string Info;
    }
    
    private string encode_subfiles(string[] text) {
        string line = "";
        for (i = 0; (i 
                    <= (text.Length - 1)); i++) {
            (text(i) + "##");
        }
        return line;
    }
    
    //  Third level data join "##"
    private string encode_file(string[] line) {
        string section = "";
        for (i = 0; (i 
                    <= (line.Length - 1)); i++) {
            (line(i) + "$$");
        }
        return section;
    }
    
    //  Second level data join "$$"
    private string encode_build(string[] section) {
        string build = "";
        for (i = 0; (i 
                    <= (section.Length - 1)); i++) {
            (section(i) + ",");
        }
        return build;
    }
    
    //  First level data join ","
    public string Encode_Request(Request req) {
        string email = "";
        string[] section = null;
        section[0] = req.Sender;
        section[1] = req.GUID;
        section[2] = req.Product;
        section[3] = req.Release;
        section[4] = req.Reference;
        section[5] = req.Description;
        string[] sourcefile = null;
        for (i = 0; (i 
                    <= (req.Sourcefiles.Length - 1)); i++) {
            sourcefile[i] = encode_subfiles(req.Sourcefiles(i));
        }
        section[6] = encode_file(sourcefile);
        string[] component = null;
        for (i = 0; (i 
                    <= (req.Components.Length - 1)); i++) {
            component[i] = encode_subfiles(req.Components(i));
        }
        section[7] = encode_file(component);
        section[8] = encode_file(req.SQL);
        section[9] = req.Impact;
        section[10] = req.Info;
        email = encode_build(section);
        return email;
    }
    
    //  Encode Request variable to request email
    private string[] decode_build(string csv) {
        string[] param = csv.Split(",");
        string[] build = null;
        int j = 0;
        for (i = 0; (i 
                    <= (param.Length - 1)); i++) {
            if (((param[i] == "") 
                        || ((param[i] == "\r") 
                        || (param[i] == "\r\n")))) {
                //  Blank space is irrelevant
            }
            else {
                build[j] = param[i];
                j++;
            }
        }
        return build;
    }
    
    //  First level data split ","
    private string[] decode_files(string csv) {
        string[] param = csv.Split("$$");
        string[] files = null;
        int j = 0;
        for (i = 0; (i 
                    <= (param.Length - 1)); i++) {
            if (((param[i] == "") 
                        || ((param[i] == "\r") 
                        || (param[i] == "\r\n")))) {
                //  Blank space is irrelevant
            }
            else {
                files[j] = param[i];
                j++;
            }
        }
        return files;
    }
    
    //  Second level data split "$$"
    private string[] decode_subfiles(string csv) {
        string[] param = csv.Split("##");
        string[] subs = null;
        int j = 0;
        for (i = 0; (i 
                    <= (param.Length - 1)); i++) {
            if (((param[i] == "") 
                        || ((param[i] == "\r") 
                        || (param[i] == "\r\n")))) {
                //  Blank space is irrelevant
            }
            else {
                subs[j] = param[i];
                j++;
            }
        }
        return subs;
    }
    
    //  Third level data split "##"
    public Request Decode_Request(string body) {
        Request req = null;
        string[] test = decode_build(body);
        req.Sender = test[0];
        req.GUID = test[1];
        req.Product = test[2];
        req.Release = test[3];
        req.Reference = test[4];
        req.Description = test[5];
        string[] srcfiles = decode_files(test[6]);
        for (i = 0; (i 
                    <= (srcfiles.Length - 1)); i++) {
            req.Sourcefiles(i) = decode_subfiles(srcfiles[i]);
        }
        string[] components = decode_files(test[7]);
        for (i = 0; (i 
                    <= (components.Length - 1)); i++) {
            req.Components(i) = decode_subfiles(components[i]);
        }
        req.SQL = decode_files(test[8]);
        req.Info = test[9];
        return req;
    }
    
    //  Decode request email to Request variable
    private string[] decode_tasklines(string task) {
        string[] param = task.Split("\r\n");
        string[] build = null;
        int j = 0;
        for (i = 0; (i 
                    <= (param.Length - 1)); i++) {
            if (((param[i] == "") 
                        || (param[i] == " "))) {
                //  Blank space is irrelevant
            }
            else {
                build[j] = param[i];
                j++;
            }
        }
        return build;
    }
    
    //  First level of data split "vbCrLf"
    private string[] decode_subtext(string line) {
        string[] text = line.Split('\t');
        return text;
    }
    
    //  Second level of data split "vbTab"
    public Request Decode_Task(string request) {
        Request req = null;
        int iSender = 0;
        int iGUID = 0;
        int iProduct = 0;
        int iRelease = 0;
        int iReference = 0;
        int iDescription = 0;
        int iSourcefiles = 0;
        int iComponents = 0;
        int iSQL = 0;
        int iImpact = 0;
        int iInfo = 0;
        int pos = 0;
        string[] test = decode_tasklines(request);
        for (i = 0; (i 
                    <= (test.Length - 1)); i++) {
            //  Where are the parts
            if ((test[i].Contains("Sender:") == true)) {
                iSender = i;
            }
            if ((test[i].Contains("ID:") == true)) {
                iGUID = i;
            }
            if ((test[i].Contains("Product:") == true)) {
                iProduct = i;
            }
            if ((test[i].Contains("Release:") == true)) {
                iRelease = i;
            }
            if ((test[i].Contains("Reference:") == true)) {
                iReference = i;
            }
            if ((test[i].Contains("Description:") == true)) {
                iDescription = i;
            }
            if ((test[i].Contains("Sourcefiles:") == true)) {
                iSourcefiles = i;
            }
            if ((test[i].Contains("Components:") == true)) {
                iComponents = i;
            }
            if ((test[i].Contains("SQLs:") == true)) {
                iSQL = i;
            }
            if ((test[i].Contains("Impact Analysis:") == true)) {
                iImpact = i;
            }
            if ((test[i].Contains("Additional Information:") == true)) {
                iInfo = i;
            }
        }
        req.Sender = test[iSender].Substring(8);
        //  Grabs Sender email address
        req.GUID = test[iGUID].Substring(4);
        //  Grabs GUID
        req.Product = test[iProduct].Substring(9);
        //  Grabs Product
        req.Release = test[iRelease].Substring(9);
        //  Grabs Release
        req.Reference = test[iReference].Substring(11);
        //  Grabs Reference
        req.Description = test[iDescription].Substring(13);
        //  Grabs Description
        string source = "";
        for (i = iSourcefiles; (i <= iComponents); i++) {
            //  Limit lines checked for source files
            string[] file = decode_subtext(test[i]);
            //  Split lines to get file and revision
            for (j = 0; (j 
                        <= (file.Length - 1)); j++) {
                req.Sourcefiles(i)[j] = file[j];
                //  Grabs file, revision for each item in list
            }
        }
        source = "";
        for (i = iComponents; (i <= iSQL); i++) {
            //  Limit lines checked for components
            string[] file = decode_subtext(test[i]);
            //  Split lines to get file, type and build
            for (j = 0; (j 
                        <= (file.Length - 1)); j++) {
                req.Components(i)[j] = file[j];
                //  Grabs file, revision for each item in list
            }
        }
        source = "";
        for (i = iSQL; (i <= iImpact); i++) {
            //  Limit lines checked for components
            req.SQL(pos) = test[i].Replace('\t', "");
            //  Grab SQLs
        }
        req.Impact = test[iImpact];
        //  Grab Impact Analysis
        req.Info = test[iInfo];
        //  Grab Additional Information
        return req;
    }
}